using System.Web.Mvc;
using System.Web.UI;
using DnnMvcBridge.Web.Mvc.Base;
using DotNetNuke.UI.Modules;

namespace DnnMvcBridge.Web.Mvc.Filters
{
	public class DnnModuleControlAction : ActionFilterAttribute
	{

		public override void OnResultExecuting(ResultExecutingContext filterContext)
		{
			// if the model derives from the ModuleViewModelBase class then we can take the executing Dnn module instance and executing Page instance from viewdata
			// and make them available in the view by setting the ModuleViewModelBase properties here.
			
			var baseViewModel = filterContext.Controller.ViewData.Model as ModuleViewModelBase;

			if(baseViewModel != null)
			{
				baseViewModel.ModuleContext = filterContext.Controller.ViewData["ModuleContext"] as ModuleInstanceContext;
				baseViewModel.Page = filterContext.Controller.ViewData["Page"] as Page;
			}

			
		
		}

		

	}
}